package com.cen.cloud.controller;

import com.cen.cloud.pojo.Dept;
import com.cen.cloud.service.DeptClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @Author cen
 * @Date 2020/10/4 21:03
 */

@RestController
public class DeptConsumer {
    @Autowired
    private DeptClientService deptClientService=null;
    @PostMapping("/consumer/dept/add")
    public boolean add(Dept dept){
        return deptClientService.addDept(dept);
    }
    @GetMapping("/consumer/dept/getByID/{id}")
    public Dept get(@PathVariable("id") Long id){
        return deptClientService.getByID(id);
    }
    @GetMapping("/consumer/dept/get")
    public List<Dept> getAll(){
        return deptClientService.getAll();
    }


//    @Autowired
//    private RestTemplate restTemplate;
//
//    private static final String URL = "http://CLOUD-PROVIDER-DEPT";

//    @PostMapping("/consumer/dept/add")
//    public boolean add(Dept dept){
//        return restTemplate.postForObject(URL+"/dept/add",dept,Boolean.class);
//    }
//    @GetMapping("/consumer/dept/{id}")
//    public Dept get(@PathVariable("id") Long id){
//        return restTemplate.getForObject(URL+"/dept/getByID/"+id,Dept.class);
//    }
//    @GetMapping("/consumer/dept/get")
//    public List<Dept> getAll(){
//        return restTemplate.getForObject(URL+"/dept/get",List.class);
//    }
}
